package com.zhongzhi.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zhongzhi.service.AisleService;
import com.zhongzhi.springboot.pojo.Aisle;
import com.zhongzhi.springboot.pojo.Bo;
import com.zhongzhi.springboot.pojo.JsonResult;


/**
 * 通道业务层
 * @author Administrator
 *
 */

@RestController
@RequestMapping("/aisle/")
public class AisleController {

	@Autowired
	private AisleService aisleService;
	
	//1:增加通道
	@RequestMapping("insert")
	public JsonResult insert(Aisle aisle) {
		Bo bo = aisleService.insert(aisle);
		if(bo.isBool()) {
			//插入数据返回id
			return new JsonResult(200,"新增通道成功",bo.getSize(),null);
		}else {
			return new JsonResult(500,"新增通道失败: "+bo.getMessage(),bo.getSize(),null);
		}
		
	}
	//2:修改通道
	@RequestMapping("update")
	public JsonResult update(Aisle aisle) {
		Bo bo = aisleService.update(aisle);
		if(bo.isBool()) {
			return new JsonResult(200,"修改通道成功",bo.getSize(),null);
		}else {
			return new JsonResult(500,"修改通道失败: "+bo.getMessage(),bo.getSize(),null);
		}
	}
	
	//3:删除通道(如果通道下面有测试数据,则不能删除)
	@RequestMapping("delete")
	public JsonResult delete(Integer id) {
		Bo bo = aisleService.delete(id);
		if(bo.isBool()) {
			return new JsonResult(200,"删除通道成功",bo.getSize(),null);
		}else {
			return new JsonResult(500,"删除通道失败: "+bo.getMessage(),bo.getSize(),null);
		}
	}
	//4:查询全部通道
	@RequestMapping("select")
	public JsonResult select(Integer pages,Integer line) {
		Bo bo = aisleService.select(pages,line);
		if(bo.isBool()) {
			return new JsonResult(200,"查询通道成功",bo.getSize(),bo.getObject());
		}else {
			return new JsonResult(500,"查询通道失败: "+bo.getMessage(),bo.getSize(),null);
		}
	}
	
	//5:查询全部通道总数
		@RequestMapping("selectSize")
		public JsonResult selectSize() {
			Bo bo = aisleService.selectSize();
			if(bo.isBool()) {
				return new JsonResult(200,"查询机型数量成功",bo.getSize(),bo.getObject());
			}else {
				return new JsonResult(500,"查询机型数量失败: "+bo.getMessage(),bo.getSize(),null);
			}
		}
	//6:查询通道(根据id查询)
	@RequestMapping("selectById")
	public JsonResult selectById(Integer id) {
		Bo bo = aisleService.selectById(id);
		if(bo.isBool()) {
			return new JsonResult(200,"查询通道成功",bo.getSize(),bo.getObject());
		}else {
			return new JsonResult(500,"查询通道失败: "+bo.getMessage(),bo.getSize(),null);
		}
	}
	
}
